<template>
    <!-- 总承包管理费 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <a-button class="mb12" icon="plus" type="primary" @click="handleManage(2)" v-btnPermission="'bm_021_add_01'"
                >新增</a-button
            >
            <a-alert class="mb12" type="info" show-icon>
                <template slot="message">
                    <span>
                        甲指单位合同额（含税）（万元）：
                        <a>{{ statistics.totalContractFeeForA }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        管理费收取金额（含税）（万元）：
                        <a>{{ statistics.totalAccumulativeManagementFee }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        管理费占比合同额(%)：
                        <a>{{ statistics.totalPercentage }}</a>
                    </span>
                </template>
            </a-alert>
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                <template slot="action" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleManage(0, record)" v-btnPermission="'bm_021_loo_04'">查看</a>
                    <!-- 编辑 -->
                    <template v-if="record.status == 'DRAFT'">
                        <a @click="handleManage(1, record)"  v-btnPermission="'bm_021_edi_02'">编辑</a>
                    </template>

                    <!-- 删除 -->
                    <span v-btnPermission="'bm_021_del_03'">
                        <a class="del_btn" @click="handleRemove(record.id)">删除</a>
                    </span>
                    </MoreButton>
                </template>
                <template slot="status" slot-scope="text, record">
                    <list-status :status="record.status" conversion="en" />
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { getContractList, delContract } from '@/api/businessAffairs/revenueAndCost'
// import { getPageUnionActivity, deleteUnionActivity, addUnionBookHouseImport } from '@/api/union/culturalActivities' // api
import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
const searchArr = [
    // 搜索框
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject
    // },
    {
        name: '甲指分包全称',
        type: 'input',
        value: 'dptNameForA'
    },
    {
        name: '是否突破总包合同条款',
        value: 'overrideTotalManagementFee',
        type: 'select',
        data: [
            {
                value: '1',
                label: '是'
            },
            {
                value: '0',
                label: '否'
            }
        ]
    },
    {
        name: '填报人',
        type: 'input',
        value: 'creatorName'
    },
    {
        name: '填报时间',
        type: 'dateRange',
        value: 'activityDate',
        attr: {
            rangeFormat: ['createTimeBegin', 'createTimeEnd']
        }
    },
    {
        name: '状态',
        value: 'status',
        type: 'select',
        data: [
            {
                value: 'DRAFT',
                label: '未提交'
            },
            {
                value: 'SUBMITTED',
                label: '已提交'
            }
        ]
    }
]
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        }
    },
    {
        title: '所属分公司',
        dataIndex: 'companyName'
    },

    {
        title: '所属项目',
        dataIndex: 'projectName'
    },
    {
        title: '甲指单位名称',
        dataIndex: 'dptNameForA',
        ellipsis: true,
        width: '200px'
    },
    {
        title: '甲指单位合同名称',
        dataIndex: 'contractNameForA',
        ellipsis: true,
        width: '200px'
    },
    {
        title: '甲指单位合同额（含税）（万元）',
        dataIndex: 'contractFeeForA'
    },
    {
        title: '管理费收取金额（含税）（万元）',
        dataIndex: 'accumulativeManagementFee'
    },
    {
        title: '管理费占比合同额',
        dataIndex: 'percentage'
    },
    {
        title: '是否突破总包合同收取管理费',
        dataIndex: 'overrideTotalManagementFee',
        customRender(text, record, index) {
            return record.overrideTotalManagementFee ? '是' : '否'
        }
    },
    {
        title: '填报人',
        dataIndex: 'creatorName'
    },
    {
        title: '填报时间',
        dataIndex: 'fillDate'
    },
    {
        title: '状态',
        dataIndex: 'status',
        scopedSlots: { customRender: 'status' }
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '180px',
        // align: 'center',
         fixed: 'right',
        scopedSlots: { customRender: 'action' }
    }
]
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            statistics: { totalAccumulativeManagementFee: 0, totalPercentage: 0, totalContractFeeForA: 0 }, //统计
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                console.log()
                const [err, res] = await getContractList(requestParameters)
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        if (res.data.length > 0) {
                            this.$nextTick(() => {
                                this.statistics.totalAccumulativeManagementFee =
                                    res.data[0].totalAccumulativeManagementFee
                                this.statistics.totalPercentage = res.data[0].totalPercentage
                                this.statistics.totalContractFeeForA = res.data[0].totalContractFeeForA
                            })
                        }
                        console.log(this.statistics)
                        resolve(res)
                    }
                })
            },
            removeApi: { remove: delContract } // api
        }
    },
    methods: {
        // 搜索
        search(value) {
            if (value.overrideTotalManagementFee) {
                value.overrideTotalManagementFee = value.overrideTotalManagementFee == '1'
            }

            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateContractManagementFee',
                query
            })
        }
    }
}
</script>
